home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-16 | 13.5 KB | 373 lines | [TEXT/CCL2] |
- (in-package "AS")
-
- ;; file: applescript-editor.lisp
- ;; an applescript editor (duhh)
- ;; TO DO:
- ;; Need to check to insure that if the contents of the buffer have changed,
- ;; before closing the editor, the applescript object gets the new changes - no
- ;; big deal right now.
-
- (require :scrolling-fred-dialog-item)
- (export '(*AS-SCRIPT-EDITOR* MAKE-APPLESCRIPT-EDITOR))
-
-
- (DEFVAR *AS-SCRIPT-EDITOR* NIL "Points to the applescript editor")
- (DEFVAR *BOGUS-SCRIPT*
- (concatenate 'string "tell application " (cl-user:make-literal-string "applicationName")
- (format nil "~%") (format nil "~%")
- "end tell" (format nil "~%"))
- )
- ;; THis is where the script is actually written
- (DEFCLASS AS-INPUT-BUFFER (ccl::scrolling-fred-dialog-item)
- ()
- (:default-initargs
- :view-size #@(450 230)
- :view-nick-name 'input-buffer
- )
- )
-
- (DEFCLASS AS-EDITOR-WINDOW (window)
- ((current.object :initarg :current-object :initform nil :accessor current-object)
- )
- (:default-initargs
- :window-type :document-with-grow
- :color-p t
- :window-title "AppleScript Editor"
- :view-position #@(50 100)
- :view-size #@(500 300)
- :close-box-p t
- )
- )
-
- (DEFCLASS RUN-SCRIPT-BTN (ccl::button-dialog-item)
- ()
- (:default-initargs
- :view-nick-name 'run-btn
- :default-button nil
- :dialog-item-text "Run Script"
- :view-size #@(100 20)
- :view-position #@(79 274)
- :view-font '("Chicago" 12 :SRCOR :PLAIN)
- )
- )
-
- (DEFMETHOD CCL::DIALOG-ITEM-ACTION ((btn run-script-btn))
- ;; enter the script into the applescript instance then compile and run the script.
- (let* ((dialog (view-container btn))
- (as-object (current-object dialog))
- (script (extract-script-text (dialog-item-text (view-named 'input-buffer dialog)))))
- ; set the script
- (setf (script as-object) script)
- (open-component as-object)
- (compile-applescript as-object)
- (execute-applescript as-object)
- (if (check-box-checked-p (view-named 'show-result (view-container btn)))
- (display-result as-object))
- )
- )
-
- (DEFCLASS ADD-SCRIPT-BTN (ccl::button-dialog-item)
- ()
- (:default-initargs
- :view-nick-name 'add-btn
- :default-button t
- :dialog-item-text "Add"
- :view-size #@(100 20)
- :view-position #@(183 273)
- :view-font '("Chicago" 12 :SRCOR :PLAIN)
- )
- )
-
- (DEFMETHOD CCL::DIALOG-ITEM-ACTION ((btn add-script-btn))
- ;; enter the script into the applescript instance then compile it.
- (let* ((dialog (view-container btn))
- (as-object (current-object dialog))
- (script (dialog-item-text (view-named 'input-buffer dialog))))
- ; set the script
- (setf (script as-object) script)
- ;; since we want to recompile the script set the compiled script id to nil
- (setf (compiled-script-id as-object) nil)
- ))
-
- (DEFCLASS CANCEL-BTN (ccl::button-dialog-item)
- ()
- (:default-initargs
- :view-nick-name 'cancel-btn
- :default-button nil
- :dialog-item-text "cancel"
- :view-size #@(60 20)
- :view-position #@(301 275)
- :view-font '("Chicago" 12 :SRCOR :PLAIN)
- )
- )
-
- (DEFMETHOD CCL::DIALOG-ITEM-ACTION ((btn cancel-btn))
- ;; punt
- (let ((dialog (view-container btn)))
- ; set the script
- (set-dialog-item-text (view-named 'input-buffer dialog) "")
- (setf (current-object dialog) nil)
- ))
-
-
- (DEFMETHOD SHOW-SCRIPT ((window AS-EDITOR-WINDOW) &optional (script *bogus-script*))
- ;; shove the script in the AS-INPUT-BUFFER
- (let ((input.buffer (view-named 'input-buffer window)))
- (set-dialog-item-text input.buffer script)
- )
- )
-
- (DEFUN MAKE-APPLESCRIPT-EDITOR (&optional as-object)
- (cond ((and *AS-SCRIPT-EDITOR*
- (wptr *AS-SCRIPT-EDITOR*))
- (window-select *AS-SCRIPT-EDITOR*)
- (setf (current-object *AS-SCRIPT-EDITOR*) as-object)
- )
- (t
- (setf *AS-SCRIPT-EDITOR*
- (make-instance 'as-editor-window))
- (setf (current-object *AS-SCRIPT-EDITOR*) as-object)
- (let* ((v-offset 20)
- (h-offset 15)
- (dialog-size (view-size *AS-SCRIPT-EDITOR*))
- (dialog-width (point-h dialog-size))
- (dialog-height (point-v dialog-size))
- (reserve-for-button 50)
- (button-margin (floor
- (/ (- (point-h dialog-width)
- 280 ;sum of buttons
- ) 2)))
- (run-button-position nil)
- (add-button-position nil)
- (cancel-button-position nil))
- (setf run-button-position
- (make-point button-margin
- (- dialog-height 25)))
- (setf add-button-position
- (make-point (+ 10 (point-h run-button-position)
- 100)
- (point-v run-button-position)))
- (setf cancel-button-position
- (make-point (+ 10 (point-h add-button-position) 100)
- (point-v run-button-position)))
- (add-subviews *AS-SCRIPT-EDITOR*
- (make-instance 'check-box-dialog-item
- :view-position #@(0 0)
- :dialog-item-text "Show The Result?"
- :check-box-checked-p t
- :view-nick-name 'show-result)
- (make-instance 'as-input-buffer
- :view-position (make-point 0 v-offset)
- :view-size (make-point
- (- dialog-width
- h-offset)
- (- dialog-height
- v-offset
- reserve-for-button)))
- (make-instance 'run-script-btn
- :view-position run-button-position)
- (make-instance 'add-script-btn
- :view-position add-button-position)
- (make-instance 'cancel-btn
- :view-position cancel-button-position)))))
- )
-
- ;;(make-applescript-editor)
-
- (defmethod ccl::set-view-size ((window AS-EDITOR-WINDOW) h &optional v)
- ;; do the regular thing
- (declare (ignore v))
- (call-next-method)
- ;; resize the input-buffer proportionally
-
- (let* ((v-offset 20)
- (h-offset 15)
- (dialog-width (point-h h))
- (dialog-height (point-v h))
- (reserve-for-button 50)
- (button-margin (floor
- (/ (- dialog-width
- 280 ;sum of buttons
- ) 2)))
- (run-button-position nil)
- (add-button-position nil)
- (cancel-button-position nil))
- (setf run-button-position
- (make-point button-margin
- (- dialog-height 25)))
- (setf add-button-position
- (make-point (+ 10 (point-h run-button-position)
- 100)
- (point-v run-button-position)))
- (setf cancel-button-position
- (make-point (+ 10 (point-h add-button-position) 100)
- (point-v run-button-position)))
- (set-view-size (view-named 'input-buffer window)
- (- dialog-width h-offset)
- (- dialog-height v-offset reserve-for-button))
- (set-view-position (view-named 'run-btn window) (point-h run-button-position)
- (point-v run-button-position))
- (set-view-position (view-named 'add-btn window) (point-h add-button-position)
- (point-v add-button-position))
- (set-view-position (view-named 'cancel-btn window) (point-h cancel-button-position)
- (point-v cancel-button-position))
- )
- )
-
- ;; Method for editing scripts using the applescript-editor
-
- (DEFMETHOD EDIT-SCRIPT ((ASO APPLESCRIPT-OBJECT))
- (declare (special *AS-SCRIPT-EDITOR*))
- (let ((script (script ASO))
- (theApp (application-name ASO)))
- (if (and script
- (not (cl-user:null-string-p script)))
- (progn
- (make-applescript-editor ASO)
- (show-script *AS-SCRIPT-EDITOR* script))
- (progn
- (make-applescript-editor ASO)
- (if theApp
- (show-script *AS-SCRIPT-EDITOR*
- (concatenate 'string "tell application"
- (cl-user:make-literal-string theApp)
- " to")))))
- )
- )
-
-
-
- ;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- (defclass aso-create-btn (ccl::button-dialog-item)
- ()
- (:default-initargs
- :view-nick-name 'save
- :default-button t
- :dialog-item-text "Save"
- :view-position #@(13 237)
- :view-size #@(62 16)
- :view-font '("Chicago" 12 :SRCOR :PLAIN)
- )
- )
-
- (defclass aso-abort-btn (ccl::button-dialog-item)
- ()
- (:default-initargs
- :view-nick-name 'abort
- :dialog-item-text "Abort"
- :view-position #@(11 271)
- :view-size #@(62 16)
- :view-font '("Chicago" 12 :SRCOR :PLAIN)
- )
- )
- ;;; An applescript object editor - which generates an applescript object with
- ;;; an editcript pane.
-
- (defun make-aso-editor (&optional applescript-object)
- ;;
- (let* ((window (make-instance 'AS-editor-window
- :window-title "Applescript object builder"
- :color-p t
- :view-position #@(45 100)
- :view-size #@(450 325)
- ))
- (as-edit-buffer (make-instance 'as-input-buffer
- :view-position #@(130 90)
- :view-size #@(290 200)
- :view-nick-name 'input-buffer))
-
- (app-name-label (make-instance 'STATIC-TEXT-DIALOG-ITEM
- :view-position #@(6 31)
- :view-size #@(128 21)
- :dialog-item-text "Application name"
- ))
-
- (as-radio (make-instance 'RADIO-BUTTON-DIALOG-ITEM
- :view-position #@(10 96)
- :view-size #@(97 16)
- :dialog-item-text "AppleScript"
- :radio-button-pushed-p t))
-
- (app-name-field (make-instance 'EDITABLE-TEXT-DIALOG-ITEM
- :view-position #@(142 34)
- :view-size #@(167 17)
- :view-nick-name 'app-name))
-
- (ht-radio (make-instance 'RADIO-BUTTON-DIALOG-ITEM
- :view-position #@(10 120)
- :view-size #@(88 16)
- :dialog-item-text "HyperTalk"
- :dialog-item-enabled-p nil))
- (qk-radio (make-instance 'RADIO-BUTTON-DIALOG-ITEM
- :view-position #@(10 146)
- :view-size #@(93 16)
- :dialog-item-text "QuickKeys"
- :dialog-item-enabled-p nil))
- (create-btn (make-instance 'ASO-CREATE-BTN))
- (abort-btn (make-instance 'ASO-ABORT-BTN))
- )
- (add-subviews window as-edit-buffer app-name-field app-name-label
- as-radio ht-radio
- qk-radio create-btn abort-btn)
- (cond (applescript-object
- (set-dialog-item-text as-edit-buffer (or (script applescript-object)
- ""))
- (set-dialog-item-text app-name-field (or (application-name applescript-object)
- ""))
- (radio-button-push (case (scripting-component-type applescript-object)
- ((:|ascr| $AppleScript) as-radio))))
- (t (setf applescript-object (make-instance 'applescript-object))
- ))
- (setf (current-object window) applescript-object)
- window))
-
-
- ;;
- (defmethod ccl::dialog-item-action ((btn aso-create-btn))
- ;; gather up all the information in the views of the window and change the
- ;; values in the applescript-object
- (let* ((win (view-container btn))
- ;; this is only applescript
- (script.type (string-downcase (dialog-item-text (pushed-radio-button win 0))))
- (appname (dialog-item-text (view-named 'app-name win)))
- (script (extract-script-text (dialog-item-text (view-named 'input-buffer win))))
- (as-object (current-object win)))
-
- ;; set the values in the current object of the window
- (setf (application-name as-object) appname
- (script as-object) script
- (compiled-script as-object) nil ; script changed, recompile
- (scripting-component-type as-object) (if (string= script.type
- "applescript")
- $AppleScript
- $HyperTalk))
- )
- )
-
- ;; what should abort do? SHould it revert all the fields to the original
- ;; state, or should it just put everything away and quit? I choose the latter.
- (defmethod ccl::dialog-item-action ((btn aso-abort-btn))
- ;; gather up all the information in the views of the window and change the
- ;; values in the applescript-object
- (let ((win (view-container btn)))
- (setf (current-object win) nil)
- (set-dialog-item-text (view-named 'app-name win) "")
- (set-dialog-item-text (view-named 'input-buffer win) "")
- (window-close win)
- )
- )
-
-
- (defmethod edit-applescript-object ((aso applescript-object))
- (make-aso-editor aso))
-
- ;;(setf ttest (make-instance 'applescript-object))
- ;;(edit-applescript-object ttest)
-
-
-
- (provide :as-edit)
-
-
-